# -*- coding: utf-8 -*-
# @Time : 2023/11/29 19:37
# @Author : 支晓光
# @Email : 1473858993@qq.com
# @File : oxman.py
# @Project : YouGuuUII
import logging
from time import sleep
from conftest import driver
from appium.webdriver.common.appiumby import AppiumBy
from common.base_page import BasePage

package = 'com.jhss.youguu'
activity = '.ui.DesktopActivity'


class OxMan(BasePage):
    # 牛人
    btn_desktop_superman = AppiumBy.ID, 'com.jhss.youguu:id/btn_desktop_superman'
    # 搜索框
    ll_fake_search_btn = AppiumBy.ID, 'com.jhss.youguu:id/ll_fake_search_btn'
    # 输入
    et_stock_search = AppiumBy.ID, 'com.jhss.youguu:id/et_stock_search'
    # 关注状态
    tv_spm_follow_text = AppiumBy.ID, 'com.jhss.youguu:id/tv_spm_follow_text'
    # 头像
    head_pic = AppiumBy.ID, 'com.jhss.youguu:id/head_pic'
    # 关注
    btn_focus = AppiumBy.ID, 'com.jhss.youguu:id/btn_focus'
    # 名字定位
    nickNameView = AppiumBy.ID, 'com.jhss.youguu:id/nickNameView'
    # 没有找到对象
    tv_tips = AppiumBy.ID, 'com.jhss.youguu:id/tv_tips'
    # 关注
    bt_send_bull = AppiumBy.ID,'com.jhss.youguu:id/bt_send_bull'
    # 取消关注
    tv_follow_text = AppiumBy.ID,'com.jhss.youguu:id/tv_follow_text'



    def serch_leter_follor(self, text):
        # 点击牛人
        self.click_ele(self.btn_desktop_superman)
        # 点击搜索框
        self.click_ele(self.ll_fake_search_btn)
        sleep(1)
        # 点击搜索牛人
        self.tap(676, 172)
        # 输入文本
        self.send_keys(self.et_stock_search, text)
        try:
            # 抓取"抱歉"文本
            self.not_find = self.find_element(self.tv_tips)
            self.not_find = self.not_find.text
            self.status = 1
        except:
            # 赋值为空
            self.status = 0
            print(self.status)
            # 抓取名字定位
            try:
                # 查询元素为多个名称
                self.name = self.find_elements(self.nickNameView)
                print('name1')
            except:
                # 查询为单个元素
                self.name = self.find_element(self.nickNameView)
                print('name2')

        if self.status == 0:
            if len(self.name) == 1:
                self.status1 = self.find_element(self.tv_spm_follow_text).text
                print(self.status1)
                if self.status1 == '已关注':
                    print('1.1')
                    self.click_ele(self.tv_spm_follow_text)
                    print('1')
                self.click_ele(self.nickNameView)
                print('2')
                self.click_ele(self.bt_send_bull)
                print('3')
                self.unfollow = self.find_element(self.tv_follow_text).text
                print('4')
            else:
                self.status1 = self.find_elements(self.tv_spm_follow_text)[0].text
                if self.status1 == '已关注':
                    print('1')
                    a = self.find_elements(self.tv_spm_follow_text)[0]
                    a.click()
                    print('2')
                b = self.find_elements(self.nickNameView)[0]
                b.click()
                print('3')
                self.click_ele(self.bt_send_bull)
                print('4')
                self.unfollow = self.find_element(self.tv_follow_text).text
                print('5')

            driver.start_activity(package,activity)
            # self.nickNameView
            self.click_ele(self.head_pic)
            self.click_ele(self.btn_focus)
            self.follorname = self.find_elements(self.nickNameView)
            self.l = []
            for i in self.follorname:
                self.l.append(i.text)
            print(self.l)